package net.organizer.ui.actionhandler;

import net.organizer.dao.Domain;

import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.googlecode.objectify.NotFoundException;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import net.organizer.ui.actionhandler.message.UnknownEntityMessage;
import net.organizer.dao.Person;

public class PersonGetOneActionHandler extends ActionHandlerBase {
private static final Logger logger = Logger.getLogger(PersonGetOneActionHandler.class.getName());

@Override
public void handleAction(HttpServletRequest req, JSONObject respJSONObject) throws Exception {
  logger.fine("handleAction");
  long id = getParamValueAsLong(req, "id", true);
  try {
    Domain domain = new Domain();
    domain.setName("domain1");
    Objectify ofy = ObjectifyService.begin();
    logger.fine("handleAction... id: " + id);
    Person person = ofy.get(Person.getKey(domain, id));
    respJSONObject.put("person", person.toJSONObject());
  }
  catch (NotFoundException e) {
    new UnknownEntityMessage(id, respJSONObject);
  }
}
}
